<template>
	<uni-popup ref="popup" type="center" border-radius="10px" :mask-click="false" :is-mask-click="false">
		<view class="modal">
			<text class="title">{{ title }}</text>
			<view class="content">
				<text class="txt">{{ content }}</text>
			</view>
			<view class="btns">
				<button size="default" class="btnDefault cancel" hover-class="btnHover"
					@click="modalCancel">{{cancelTxt}}</button>
				<button v-if="mode===0" size="default" class="btnDefault submit" hover-class="btnHover"
					@click="modalConfirm">{{confirmTxt}}</button>
				<button v-else-if="mode===1" class="btnDefault contact" open-type="contact" session-from="sessionFrom"
					show-message-card="true" @click="modalConfirm">
					{{confirmTxt}}
				</button>
				<button v-else size="default" class="btnDefault submit" hover-class="btnHover"
					@click="modalCancel">{{confirmTxt}}</button>
			</view>
		</view>
	</uni-popup>
</template>

<script>
	import mixins from '@/common/mixins.js';
	export default {
		name: "zkModal",
		data() {
			return {
				mode: 0, // 0-常规；1-打开微信客服
				title: '',
				content: '',
				cancelTxt: '',
				confirmTxt: '',
				resolve: null,
				reject: null,
			};
		},
		computed: {},
		mixins: [mixins],
		methods: {
			show(options) {
				this.mode = options.mode || 0;
				this.title = options.title || "温馨提示";
				this.content = options.content || "";
				this.cancelTxt = options.cancelTxt || "取消";
				this.confirmTxt = options.confirmTxt || "确定";
				this.$refs.popup.open();
				return new Promise((resolve, reject) => {
					this.resolve = resolve;
					this.reject = reject;
				});
			},
			modalConfirm(e) {
				this.resolve(true);
				this.$refs.popup.close();
			},
			modalCancel(e) {
				this.resolve(false);
				this.$refs.popup.close();
			},

			// async demo(){
			// 	const modelRes = await this.$utils.showModal(this, {
			// 		title: '温馨的提示',
			// 		content: '显示模态弹窗，可以只有一个确定按钮，也可以同时有确定和取消按钮。',
			// 	});
			// 	console.log("modelRes", modelRes); // true/false
			// }

		}
	}
</script>

<style lang="scss" scoped>
	.modal {
		width: 560rpx;
		border-radius: 20rpx;
		display: flex;
		flex-direction: column;
		background: #fff;

		.title {
			width: 100%;
			height: 80rpx;
			font-weight: 400;
			font-size: 32rpx;
			color: #191919;
			line-height: 80rpx;
			text-align: center;
		}

		.content {
			padding: 30rpx;
			width: calc(100% - 60rpx);

			.txt {
				font-weight: 400;
				font-size: 28rpx;
				color: #7F7F7F;
				text-align: justify;
				word-break: break-all;
				line-height: 1.5;
			}
		}

		.btns {
			margin: 30rpx;
			width: calc(100% - 60rpx);
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;

			.btnDefault {
				width: 45%;
				height: 80rpx;
				box-shadow: none;
				border: 1rpx solid #fff;
				color: #fff;
				font-size: 30rpx;
			}

			.cancel {
				background: $uni-bg-color;
				color: $uni-base-color;
			}

			.submit {
				background: $uni-primary;
			}

			.contact {
				width: max-content;
				background: $uni-primary;
			}
		}
	}
</style>